import pytest
from time import sleep
from Datas.GobalDatas import gobal_datas as GD
from Datas.LoginDatas.login_datas import success_data as LD
from PageObjects.LoginPage.login_page import LoginPage
from PageObjects.PersonalCodePage.personalcode_page import PersonalcodePage
from Common.plugs.get_log import logger

driver = None


@pytest.fixture(scope='class')
def start_module(project_module_start):
    """
    #scope='class'，每个class执行1次
    每个模块单独打开一次浏览器
    :param project_module_start:  每个模块单独打开一次浏览器
    :return: driver pg
    """
    logger.info("==========开始执行测试用例集===========")
    global driver
    driver = project_module_start
    logger.info("----------------------------------------------------------------------------------" + str(driver))
    driver.get(GD.LOGIN)
    LoginPage(driver).login(LD['PHONE'], LD['PASSWORD'])
    sleep(2)
    driver.get(GD.PERONAL_CODE__EMPLOYEE_URL)
    pg = PersonalcodePage(driver)
    yield (driver, pg)
    logger.info("==========结束执行测试用例集===========")


@pytest.fixture(scope='class')
def start_session(project_session_start):
    """
    #scope='class'，每个class执行1次
    所有模块只打开一次浏览器
    :param project_session_start: 所有模块只打开一次浏览器,不需要重新登录
    :return: driver pg
    """
    logger.info("==========开始执行测试用例集===========")
    global driver
    driver = project_session_start
    logger.info("----------------------------------------------------------------------------------" + str(driver))
    # driver.get(GD.LOGIN)
    # LoginPage(driver).login(LD['PHONE'], LD['PASSWORD'])
    # sleep(2)
    driver.get(GD.PERONAL_CODE__EMPLOYEE_URL)
    pg = PersonalcodePage(driver)
    yield (driver, pg)
    logger.info("==========结束执行测试用例集===========")


@pytest.fixture()
def refresh_page():
    yield
    sleep(3)
